var a = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/defineProperty"), e = require("../../../@babel/runtime/helpers/asyncToGenerator"), d = getApp(), i = require("../../../mybehaviors/imageSrcP"),h = require("../../../host");

Component({
    behaviors: [ i ],
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        page_id: {
            type: null
        },
        index: {
            type: null
        },
        U_tabcontrol: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        isLast: {
            type: null
        },
        plugin_active: {
            type: null
        },
        store_alone_temp: {
            type: null
        },
        childComponent: {
            type: null,
            value: "goods"
        },
        childStyle: {
            type: null,
            value: ""
        },
        indTab: {
            type: null
        },
        indexTab: {
            type: null
        },
        infoTab: {
            type: null
        },
        second_list_key: {
            type: null
        },
        all: {
            type: null
        },
        totalAll: {
            type: null
        },
        store_id: {
            type: null
        }
    },
    data: {
        integral: "积分",
        showList: !1,
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        list: [],
        language: "",
        alreadyHandleArray: [],
        arrIndex: 1,
        market_price_text: "",
        price_text: "",
        goods_cofig: [],
        per_page: 12,
        page: 1,
        total_page: 0,
        isLoadMore: !0,
        allLoaded: !1,
        isprice:true
    },
    lifetimes: {
        attached: function() {
            var a = wx.getStorageSync("langIndex");
            this.setData({
                language: a.en,
                thumb_parameter: this.getyz_basic_info()
            });
            var t = wx.getStorageSync("yz_basic_info").lang.goods, e = t && t.price ? t.price : "现价", d = t && t.market_price ? t.market_price : "原价", i = t && t.vip_price ? t.vip_price : "会员价", s = wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show && 1 == wx.getStorageSync("yz_basic_info").home.mailInfo.scribing_show ? 1 : 0;
            this.setData({
                price_text: e,
                market_price_text: d,
                vip_price_txt: i,
                scribing_show: s
            });
            var r = wx.getStorageSync("integral");
            r && this.setData({
                integral: r
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        });
        // let de = wx.getStorageSync('new_decorate').item
        if(h.uniacid == "96"){
            this.setData({
                isprice : false
            })
        }
        var a = wx.getStorageSync("yz_basic_info");
        a.home.plugin && a.home.plugin.goods_show && this.setData({
            goods_cofig: a.home.plugin.goods_show.goods_group,
            goods_style_set: a.plugin_setting.good_style
        }), "goods" == this.data.childComponent ? this.data.datas.list.data ? (this.setData({
            total_page: this.data.datas.list.last_page,
            page: this.data.datas.list.current_page,
            per_page: this.data.datas.list.per_page,
            alreadyHandleArray: this.data.datas.list.data,
            list: this.data.datas.list.data.slice(0, this.data.per_page)
        }), this.data.total_page <= this.data.page && this.setData({
            isLoadMore: !1,
            allLoaded: !0
        }), this.data.datas.get_number && this.data.datas.get_number <= this.data.per_page && this.setData({
            isLoadMore: !1,
            allLoaded: !0,
            list: this.data.datas.list.data.slice(0, this.data.datas.get_number)
        })) : this.setData({
            isLoadMore: !1,
            allLoaded: !0,
            list: this.data.datas.list
        }) : (this.setData({
            total_page: this.data.datas.list.last_page,
            page: this.data.datas.list.current_page,
            per_page: this.data.datas.list.per_page,
            alreadyHandleArray: this.data.datas.list.data,
            list: this.data.datas.list.data
        }), this.data.total_page <= this.data.page && this.setData({
            isLoadMore: !1,
            allLoaded: !0
        })), this.setData({
            showList: !0
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        tabTwoContro: function(a, t) {
            var e = this;
            "tab" == this.data.childComponent && (wx.showLoading({
                title: "加载中",
                icon: "none"
            }), this.data.list = [], this.setData({
                total_page: a.last_page,
                page: a.current_page,
                per_page: a.per_page,
                alreadyHandleArray: a.data,
                list: a.data
            }, function(a) {
                wx.hideLoading({}), e.triggerEvent("onReadEnd", {
                    index: t
                });
            }), this.data.total_page <= this.data.page && this.setData({
                isLoadMore: !1,
                allLoaded: !0
            }));
        },
        getKeyInd: function(a, t) {
            var e = this;
            return new Promise(function(t, d) {
                a[e.data.indexTab].forEach(function(a, e) {
                    a.tabSelectShow == a.id && t(a);
                });
            });
        },
        getAllKey: function(a, t) {
            return new Promise(function(e, d) {
                t.second_list.forEach(function(t, d) {
                    t.id == a.id && e(d);
                });
            });
        },
        getMoreDataTest: function(i) {
            var s = this;
            return e(a.default.mark(function e() {
                var i, r, n, o, l, g, p;
                return a.default.wrap(function(a) {
                    for (;;) switch (a.prev = a.next) {
                      case 0:
                        return i = s.data.indexTab, r = s.data.indTab, n = s.data.infoTab, o = {
                            page: s.data.page + 1,
                            decorate_id: s.data.page_id,
                            component_id: s.data.component_id,
                            component_key: "U_moretabcontrol"
                        }, s.setData({
                            page: s.data.page
                        }), a.next = 7, s.getKeyInd(s.data.all, n);

                      case 7:
                        return l = a.sent, a.next = 10, s.getAllKey(l, s.data.totalAll);

                      case 10:
                        g = a.sent, o.component_info = {
                            list_key: i,
                            second_list_key: g,
                            components_key: r
                        }, o.component_info = JSON.stringify(o.component_info), wx.showLoading({
                            title: "加载中"
                        }), s.properties.store_id && (o.store_id = s.properties.store_id), p = d.getNetAddresss("home-page.get-decorate-page"), 
                        d._getNetWork({
                            url: p,
                            data: o,
                            success: function(a) {
                                if (1 == a.data.result) {
                                    var e, d, i = a.data.data;
                                    d = s.data.list.concat(i.data), s.setData((e = {
                                        total_page: i.last_page,
                                        page: i.current_page
                                    }, t(e, "infoTab.remote_data.list.current_page", i.current_page), t(e, "infoTab.remote_data.list.last_page", i.last_page), 
                                    t(e, "list", d), e));
                                }
                                wx.hideLoading({
                                    success: function(a) {}
                                });
                            },
                            fail: function(a) {
                                wx.hideLoading({
                                    success: function(a) {}
                                }), console.log(a);
                            }
                        });

                      case 17:
                      case "end":
                        return a.stop();
                    }
                }, e);
            }))();
        },
        gotoDetail: function(a) {
            var t = a.currentTarget.dataset.item.id, e = a.currentTarget.dataset.item.category_option_id ? "&coid=".concat(a.currentTarget.dataset.item.category_option_id) : "";
            69 == a.currentTarget.dataset.item.plugin_id ? wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t + "&name=69" + e
            }) : 78 == a.currentTarget.dataset.item.plugin_id ? wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t + "&md=1" + e
            }) : wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t + e
            });
        },
        openShare: function(a) {
            var t = a.target.dataset.item || a.currentTarget.dataset.item;
            this.triggerEvent("componentGoodShare", t);
        },
        getMoreData: function() {
            var a = this, t = this;
            if (this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length >= this.data.per_page) return t.setData({
                list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }), void (this.data.datas.get_number && this.data.list.length > this.data.datas.get_number && this.setData({
                isLoadMore: !1,
                allLoaded: !0,
                list: this.data.list.slice(0, this.data.datas.get_number)
            }));
            if (this.setData({
                isLoadMore: !1
            }), t.data.page >= t.data.total_page) this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && t.setData({
                list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }), this.data.datas.get_number && this.data.list.length > this.data.datas.get_number && this.setData({
                list: this.data.list.slice(0, this.data.datas.get_number)
            }); else {
                t.setData({
                    page: t.data.page + 1
                });
                var e = d.getNetAddresss("home-page.get-decorate-page");
                e += "&page=" + t.data.page, e += "&decorate_id=" + t.data.page_id, e += "&component_id=" + t.data.component_id, 
                this.data.U_tabcontrol ? (e += "&component_key=U_tabcontrol", e += "&component_info=" + JSON.stringify({
                    list_key: this.data.index
                })) : e += "&component_key=U_goods", this.properties.store_id && (e += "&store_id=".concat(this.properties.store_id)), 
                d._getNetWork({
                    url: e,
                    success: function(e) {
                        var d = e.data;
                        if (1 == d.result) {
                            var i = t.data.list;
                            a.data.U_tabcontrol ? (t.setData({
                                page: d.data[0].remote_data.list.current_page || a.data.page,
                                alreadyHandleArray: a.data.alreadyHandleArray.concat(d.data[0].remote_data.list.data)
                            }), t.setData({
                                list: i.concat(a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex, a.data.per_page * (a.data.arrIndex + 1))),
                                arrIndex: a.data.arrIndex + 1
                            }), a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex).length > 0 || t.data.page < t.data.total_page ? t.setData({
                                isLoadMore: !0
                            }) : t.setData({
                                allLoaded: !0
                            })) : (t.setData({
                                page: d.data.current_page || a.data.page,
                                alreadyHandleArray: a.data.alreadyHandleArray.concat(d.data.data)
                            }), t.setData({
                                list: i.concat(a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex, a.data.per_page * (a.data.arrIndex + 1))),
                                arrIndex: a.data.arrIndex + 1
                            }), a.data.alreadyHandleArray.slice(a.data.per_page * a.data.arrIndex).length > 0 || t.data.page < t.data.total_page ? t.setData({
                                isLoadMore: !0
                            }) : t.setData({
                                allLoaded: !0
                            })), a.data.datas.get_number && a.data.list.length > a.data.datas.get_number && a.setData({
                                isLoadMore: !1,
                                allLoaded: !0,
                                list: a.data.list.slice(0, a.data.datas.get_number)
                            });
                        } else t.setData({
                            page: t.data.page - 1,
                            isLoadMore: !1,
                            allLoaded: !0
                        });
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            }
        },
        loadMoreMemberData: function() {
            var a = this, t = this;
            if (t.setData({
                isLoadMore: !1
            }), t.data.page >= t.data.total_page) this.data.alreadyHandleArray.slice(12 * this.data.arrIndex).length > 0 && t.setData({
                list: this.data.list.concat(this.data.alreadyHandleArray.slice(12 * this.data.arrIndex, 12 * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }); else {
                t.setData({
                    page: t.data.page + 1
                });
                var e = d.getNetAddresss("member.member.plugin-data");
                1 == this.data.store_alone_temp ? e = d.getNetAddresss("plugin.store-alone-temp.frontend.member.nav-data") : 2 == this.data.store_alone_temp && (e = d.getNetAddresss("plugin.store-alone-temp.frontend.home.nav-data")), 
                e += "&page=" + t.data.page, e += "&code=" + t.data.plugin_active, d._getNetWork({
                    url: e,
                    success: function(e) {
                        var d = e.data;
                        if (1 == d.result) {
                            var i = t.data.list;
                            t.setData({
                                page: d.data.data.current_page || a.data.page,
                                alreadyHandleArray: a.data.alreadyHandleArray.concat(d.data.data.data)
                            }), t.setData({
                                list: i.concat(a.data.alreadyHandleArray.slice(12 * a.data.arrIndex, 12 * (a.data.arrIndex + 1))),
                                arrIndex: a.data.arrIndex + 1
                            }), t.data.page < t.data.total_page ? t.setData({
                                isLoadMore: !0
                            }) : t.setData({
                                allLoaded: !0
                            }), t.triggerEvent("setLoadMore", {
                                isLoadMore: t.data.isLoadMore
                            });
                        } else t.setData({
                            page: t.data.page - 1,
                            isLoadMore: !1,
                            allLoaded: !0
                        });
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            }
        }
    },
    observers: {
        bottomShowBol: function(a) {
            console.log(a), "tab" != this.data.childComponent && (this.data.U_tabcontrol ? a && this.data.isLast && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
                list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }) : a && this.data.bottomShowBolIndex == this.data.index && 5 != this.data.datas.sort_style.choose_icon && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
                list: this.data.list.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }));
        }
    }
});